<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>

  <title>商品推荐</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
	 <script>
		 $(function() {
			 mallProductRecommendModule.init();
		 });
		 var mallProductRecommendModule = (function(){
			 var fileChange = function () {
				 $("#image").bind("change", function(e){
					 var file = e.target.files || e.dataTransfer.files;
					 if (file) {
						 var reader = new FileReader();
						 reader.onload = function () {
							 $("#imageUrl").attr("src", this.result);
						 };
						 reader.readAsDataURL(file[0]);
					 }
				 })
			 }

			 var typeChange = function () {
				 $("#recommendtype").bind("change", function(e){
					 var productId = $("#productid").val();
					 var type = $(this).val();
					 $("#recommendtype_v").val(type);
					 if(type != null && type != "" && typeof(type) != "undefined"){
						 $.ajax({
							 async : true,
							 type : 'POST',
							 dataType:'json',
							 url : 'mallProductRecommendController/isHave.do',// 请求的action路径
							 data : {'productid':productId,'recommendtype':type},
							 success : function(data) {
								 if (!data.success) {
									 $.messager.alert('错误',data.msg,'',function(){
										 $("#recommendtype").val(null);
										 $("#recommendtype_v").val(null);
									 })

								 }
							 },
							 error : function() {// 请求失败处理函数

							 }
						 });
					 }
				 })
			 }

			 var module = {
				 init :function(){
					 fileChange();
					 typeChange();
				 },
			 }
			 return module;
		 })();

	 </script>
 </head>
 <body style="overflow-y: hidden" scroll="no">
  <form id="formobj" name="formobj" method="post"  enctype="multipart/form-data"   action="mallProductRecommendController.do?save">
			<input id="id" name="id" type="hidden" value="${mallProductRecommendPage.id }">
	  		<input id="btn_sub" class="btn_sub" type="hidden">
	  		<input id="recommendtype_v" name="recommendtype" type="hidden" value="${mallProductRecommendPage.recommendtype}">
			<table style="width: 600px;" cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品id:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="productid" name="productid"
							   value="${mallProductRecommendPage.productid}" readonly="true">
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品名称:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="productname" name="productname"
							   value="${mallProductRecommendPage.productname}" datatype="*">
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品图片:
						</label>
					</td>
					<td class="value">
						<input type="file"  id="image"  name="image"  <c:if test="${mallProductRecommendPage.imagesrc == null}">datatype="*"</c:if>>
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品图片:
						</label>
					</td>
					<td class="value">
						<div id="imageShow"> </div>
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							旧图片:
						</label>
					</td>
					<td class="value">
						<img id="imageUrl" width="250px" height="150px" <c:if test="${mallProductRecommendPage.imagesrc != null}"> src="${mallProductRecommendPage.imagesrc}"</c:if>>
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							商品类型:
						</label>
					</td>
					<td class="value">
						<select  datatype="*" id="recommendtype" <c:if test="${mallProductRecommendPage.id != null}"> disabled </c:if>>
							<option value="">请选择</option>
							<option value="1" <c:if test="${mallProductRecommendPage.recommendtype == 1}"> selected</c:if>>每日推荐</option>
							<option value="2" <c:if test="${mallProductRecommendPage.recommendtype == 2}"> selected</c:if>>拉货宝精选</option>
						</select>
						<span class="Validform_checktip"></span>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							排序:
						</label>
					</td>
					<td class="value">
						<input class="inputxt" id="sort" name="sort"
							   value="${mallProductRecommendPage.sort}" datatype="n" <c:if test="${mallProductRecommendPage.id != null}"> readonly="true"</c:if>  >
						<span class="Validform_checktip"></span>
					</td>
				</tr>
			</table>
		</form>
  <link type="text/css" href="plug-in/Validform/css/metrole/style.css" rel="stylesheet">
  <link type="text/css" href="plug-in/Validform/css/metrole/tablefrom.css" rel="stylesheet">
  <script src="plug-in/Validform/js/Validform_v5.3.1_min_zh-cn.js" type="text/javascript"></script>
  <script src="plug-in/Validform/js/Validform_Datatype_zh-cn.js" type="text/javascript"></script>
  <script src="plug-in/Validform/js/datatype_zh-cn.js" type="text/javascript"></script>
  <script src="plug-in/Validform/plugin/passwordStrength/passwordStrength-min.js" type="text/javascript"></script>
  <script src="plug-in/jquery-plugs/form/jquery.form.js" type="text/javascript"></script>
  <script type="text/javascript">
	  $(function(){$("#formobj").Validform({
		  tiptype:4,
		  btnSubmit:"#btn_sub",
		  btnReset:"#btn_reset",
		  ajaxPost:true,
		  usePlugin:{
			  passwordstrength:{
				  minLen:6,
				  maxLen:18,
				  trigger:function(obj,error){
					  if(error){
						  obj.parent().next().find(".Validform_checktip").show();
						  obj.find(".passwordStrength").hide();
					  }else{
						  $(".passwordStrength").show();obj.parent().next().find(".Validform_checktip").hide();
					  }
				  }}
		  },
		  beforeSubmit:function(){
			  $("#formobj").ajaxSubmit({
				  type:'post',
				  url:'mallProductRecommendController.do?save',
				  dataType:'json',
				  success : function(data) {
					  var win = frameElement.api.opener;
					  if(data.success==true){
						  frameElement.api.close();
						  win.tip(data.msg);
					  }else{
						  if(data.responseText==''||data.responseText==undefined){
							  $.messager.alert('错误', data.msg);$.Hidemsg();
						  }else{
							  try{
								  var emsg = data.responseText.substring(data.responseText.indexOf('错误描述'),
										  data.responseText.indexOf('错误信息'));
								  $.messager.alert('错误',emsg);$.Hidemsg();
							  }catch(ex){
								  $.messager.alert('错误',data.responseText+"");$.Hidemsg();
							  }
						  }
						  return false;
					  }
					  win.reloadTable();
				  },
			  });
			  return false;
		  },
		  callback:function(data){

		  }
	  });});
  </script>
 </body>